# -*- coding: utf-8 -*-
import urllib.request
from urllib import request,parse


ua_header = {"User-Agent" : "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;"}

#第一种方式
# reponse=urllib.request.urlopen("https://blog.csdn.net/u011304490/article/details/80058951");
# buff=reponse.read();
# html=buff.decode("utf-8");
# print(html);

#可以添加额外信息的请求
# re=request.Request("https://blog.csdn.net/u011304490/article/details/80058951",headers=ua_header);
# buff=request.urlopen(re).read();
# html=buff.decode("utf-8");
# print(html);

# wd={"wd":"喵喵喵喵"};
# u=urllib.parse.urlencode(wd);
# print(u);
# w=parse.unquote(u,"utf-8");
# print(w);

url = "http://www.baidu.com/s"
word = {"wd":"传智播客"}
word = urllib.parse.urlencode(word)
newurl = url + "?" + word

headers={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"};
req = request.Request(newurl, headers=headers);
response = request.urlopen(req);

print (response.read());